package com.nhjf.mobile.controller.srsCallback;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.nhjf.command.comment.CreateCoursesCommentCommand;
import com.nhjf.common.page.Pagination;
import com.nhjf.mobile.common.util.SysProperties;
import com.nhjf.model.student.Student;
import com.nhjf.model.system.AdminSession;
import com.nhjf.model.system.User;
import com.nhjf.model.teachers.CoursesComment;
import com.nhjf.model.teachers.Teacher;
import com.nhjf.pojo.dto.result.ServiceResultDto;
import com.nhjf.pojo.qo.studnet.StudentQo;
import com.nhjf.pojo.qo.system.AdminSessionQo;
import com.nhjf.pojo.qo.system.UserQo;
import com.nhjf.pojo.qo.teachers.CoursesCommentQo;
import com.nhjf.pojo.qo.teachers.TeachersQo;
import com.nhjf.pojo.qo.total.CourseCountQo;
import com.nhjf.service.student.StudentService;
import com.nhjf.service.system.AdminSessionService;
import com.nhjf.service.system.UserService;
import com.nhjf.service.teachers.CoursesCommentService;
import com.nhjf.service.teachers.TeachersService;

import net.sf.json.JSONObject;

/**
 * @类功能说明：srs的HTTP回调
 * @部门：技术部
 * @作者：龚一凡
 * @版本：V1.0
 */
@Controller
@RequestMapping(value = "/srs")
public class SrsCallbackController {

	/**
	 * @throws IOException 
	 * 
	 * @方法功能说明：当客户端连接到指定的vhost和app时
	 * @修改者名字：龚一凡
	 * @修改内容：
	 * @参数：
	 * @return:
	 * @throws
	 */
	@ResponseBody
	@RequestMapping(value = "/on_connect")
	public String on_connect(HttpServletRequest request, Model model) throws IOException{
		BufferedReader reader = new BufferedReader(new InputStreamReader(request.getInputStream()));
		StringBuffer buffer = new StringBuffer();
		String line = " ";
		try {
			while ((line = reader.readLine()) != null){
			     buffer.append(line);
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println(buffer.toString());

		System.out.println("on_connect");
		return "0";
	}
	/**
	 * 
	 * @方法功能说明：当客户端关闭连接，或者SRS主动关闭连接时
	 * @修改者名字：龚一凡
	 * @修改内容：
	 * @参数：
	 * @return:
	 * @throws
	 */
	@ResponseBody
	@RequestMapping(value = "/on_close")
	public String on_close(HttpServletRequest request, Model model){

		System.out.println("on_close");
		return "0";
	}
	/**
	 * 
	 * @方法功能说明：当客户端发布流时，譬如flash/FMLE方式推流到服务器
	 * @修改者名字：龚一凡
	 * @修改内容：
	 * @参数：
	 * @return:
	 * @throws
	 */
	@ResponseBody
	@RequestMapping(value = "/on_publish")
	public String on_publish(HttpServletRequest request, Model model){

		System.out.println("on_publish");
		return "0";
	}
	/**
	 * 
	 * @方法功能说明：当客户端停止发布流时
	 * @修改者名字：龚一凡
	 * @修改内容：
	 * @参数：
	 * @return:
	 * @throws
	 */
	@ResponseBody
	@RequestMapping(value = "/on_unpublish")
	public String on_unpublish(HttpServletRequest request, Model model){

		System.out.println("on_unpublish");
		return "0";
	}
	/**
	 * 
	 * @方法功能说明：当客户端开始播放流时
	 * @修改者名字：龚一凡
	 * @修改内容：
	 * @参数：
	 * @return:
	 * @throws
	 */
	@ResponseBody
	@RequestMapping(value = "/on_play")
	public String on_play(HttpServletRequest request, Model model){

		System.out.println("on_play");
		return "0";
	}
	/**
	 * 
	 * @方法功能说明：当客户端停止播放时。备注：停止播放可能不会关闭连接，还能再继续播放。
	 * @修改者名字：龚一凡
	 * @修改内容：
	 * @参数：
	 * @return:
	 * @throws
	 */
	@ResponseBody
	@RequestMapping(value = "/on_stop")
	public String on_stop(HttpServletRequest request, Model model){

		System.out.println("on_stop");
		return "0";
	}
	/**
	 * 
	 * @方法功能说明：当DVR录制关闭一个flv文件时
	 * @修改者名字：龚一凡
	 * @修改内容：
	 * @参数：
	 * @return:
	 * @throws
	 */
	@ResponseBody
	@RequestMapping(value = "/on_dvr")
	public String on_dvr(HttpServletRequest request, Model model){

		System.out.println("on_dvr");
		return "0";
	}
}
